<template>
    <view class="list">
        <form>
            <view class="item">
                <label>性别</label>
                <radio-group class="radio-group" @change.stop.prevent="radioChange">
                    <label class="radio">
                        <radio value="0" :checked="sex == 0" color="#05C160"/>
                        男
                    </label>
                    <label class="radio">
                        <radio value="1" :checked="sex == 1" color="#05C160"/>
                        女
                    </label>
                </radio-group>
            </view>
        </form>
    </view>
</template>

<script>
var config = require('../../../config.js');
var http = require('../../../utils/httpHelper.js');
export default {
    data() {
        return {
            sex: '',
            noSave: true
        };
    }, //事件处理函数
    onLoad: function () {
        var that = this;
        let userInfo = uni.getStorageSync('user');
        that.setData({
            sex: userInfo.sex
        });
    },
    methods: {
        radioChange: function (e) {
            let userInfo = uni.getStorageSync('user');
            var val = e.detail.value;
            var data = {
                userId: userInfo.userId,
                sex: val
            };
            http.httpPutForm(config.clubApi.putSex, data, function (res) {
                if (res.code == '200') {
                    userInfo.sex = val;
                    uni.setStorageSync('user', userInfo);
                    uni.navigateBack();
                    console.log('修改性别成功');
                } else {
                    console.log('修改性别失败');
                }
            });
        }
    }
};
</script>
<style lang="scss">
@import './index.scss';
</style>
